import { Worker } from 'worker_threads';
import { dialogue } from './llm/index.js';
import { fileURLToPath } from 'url';
import path from 'path';
import { speak } from './tts/index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
 * @param {Electron.BrowserWindow} win
 */
export function startAides(win) {
    console.log('[master] AI aides started');
    const asrThread = new Worker(path.join(__dirname, 'asr/index.js'));
    asrThread.on('message', async (message) => {
        console.log(`[ASR] ${message.text}`);
        const t1 = Date.now();
        const aiResp = await dialogue(message.text);
        const t2 = Date.now();
        console.log(`[AI] ${aiResp} (${t2 - t1}ms)`);
        speak(aiResp, win);
    });
}